﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace TestLinq
{
    /// <summary>
    /// Classes for testing various linq tasks
    /// </summary>
    public class test_linq
    {
        static void Linq14()
        {
            int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 };
            int[] numbersB = { 1, 3, 5, 7, 8 };

            var test = from a in numbersA
                       where a > 5 && numbersB.Contains(a)
                       select a;


            foreach (var t in test)
            {
                Console.WriteLine(t);
            }
        }

        static void Linq1X()
        {
            int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 };
            int[] numbersB = { 1, 3, 5, 7, 8 };

            var test = from a in numbersA
                       select new { j = (a == 0) ? a : a + 1 };


            foreach (var t in test)
            {
                Console.WriteLine(t.j);
            }
        }

        static void Linq9()
        {
            string[] words = { "aPPLE", "BlUeBeRrY", "cHeRry" };
            Hashtable table = new Hashtable();
            table.Add("aPPLE", "A");
            table.Add("BlUeBeRrY", "B");
            table.Add("cHeRry", "c");

            var upperLowerWords =
                from w in words
                select new { Upper = w.ToUpper(), Lower = w.ToLower(), Code = doNothing(table[w]) };

            foreach (var ul in upperLowerWords)
            {
                Console.WriteLine("Uppercase: {0}, Lowercase: {1}, Code: {2}", ul.Upper, ul.Lower, ul.Code);
            }
        }

        static void Linqmax()
        {
            testData[] datas = { new testData(4, "Test-4"), new testData(1, "Test-1"), new testData(100, "Test-100") };
            var gh = datas.Where(m => m.N == datas.Max(p => p.N));
            Console.WriteLine(gh.First().Name);
        }

        private class testData
        {
            public string Name { set; get; }
            public int N { set; get; }
            public testData(int n, string name)
            {
                this.Name = name;
                this.N = n;
            }
        }

        static String doNothing(Object a)
        {
            return a.ToString() + " thing";
        }
    }
}
